﻿using System;
using System.Collections.Generic;
using System.Text;
using Entity;
namespace DAL
{
    public class DAL_Service
    {
        #region Task
        public static int Keyword_Add(Keyword m)
        {
            string sqlStr = string.Format("insert into Keyword(Name, Page_From, Page_To, OrderNum) values('{0}',{1},{2},0)", m.Name, m.Page_From, m.Page_To, m.OrderNum);
            return SQLiteHelper.ExecuteNonQuery(sqlStr, null);
        }
        public static int Keyword_Del(string name)
        {
            string sqlStr = string.Format("delete from Keyword where Name = '" + name + "'");
            return SQLiteHelper.ExecuteNonQuery(sqlStr, null);
        }
        public static int Keyword_Update(Keyword m, string oldKey)
        {
            string sqlStr = string.Format("update Keyword set Name = '{0}',Page_From = {1}, Page_To = {2}, OrderNum = {3} where Name = '{4}'", m.Name, m.Page_From, m.Page_To, m.OrderNum, oldKey);
            return SQLiteHelper.ExecuteNonQuery(sqlStr, null);
        }
        #endregion


        public static bool Company_Add(Company m)
        {
            if (SQLiteHelper.Query("select [Name] from Company where Name = '" + m.Name + "'").Rows.Count > 0)
            {
                return false;
            }
            else
            {
                string sqlStr = string.Format(
                    "insert into Company(Name,URL,JobList,JobURL,PhoneNumber,Linkman,Address,City,Email,PeopleCount,Profession,Website,Keyword,InsTime) " + 
                    " values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','"+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"')",
                    m.Name, m.URL, m.JobList, m.JobURL, m.PhoneNumber, m.Linkman, m.Address, m.City, m.Email, m.PeopleCount, m.Profession, m.Website, m.Keyword);
                SQLiteHelper.ExecuteNonQuery(sqlStr, null);
                return true;
            }
        }
    }
}
